package com.atom.process.cnmuseum.bm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;

import com.atom.common.activiti.HistoricTaskHandler;
import com.atom.common.activiti.RunningTaskHandler;
import com.atom.common.mb.dao.dj.DjDbrwDao;
import com.atom.common.mb.dao.dj.DjGcxxDao;
import com.atom.common.mb.dao.dj.DjMultimediaDao;
import com.atom.common.mb.dao.dj.DjTrackmessageDao;
import com.atom.common.mb.dao.dj.DjWhrlxxxDao;
import com.atom.common.mb.dao.dj.DjWhsxDao;
import com.atom.common.mb.dao.dj.DjXzxxDao;
import com.atom.common.mb.dao.dj.DjXzyxDao;
import com.atom.common.mb.dao.dj.DjYxxxDao;
import com.atom.common.mb.dao.gl.DbrwDao;
import com.atom.common.mb.dao.gl.GcxxDao;
import com.atom.common.mb.dao.gl.MultimediaDao;
import com.atom.common.mb.dao.gl.TrackmessageDao;
import com.atom.common.mb.dao.gl.WhrlxxxDao;
import com.atom.common.mb.dao.gl.WhsxDao;
import com.atom.common.mb.dao.gl.XzxxDao;
import com.atom.common.mb.dao.gl.XzyxDao;
import com.atom.common.mb.dao.gl.YxxxDao;
import com.atom.common.mb.entity.dj.DjDbrwDO;
import com.atom.common.mb.entity.dj.DjGcxxDO;
import com.atom.common.mb.entity.dj.DjMultimediaDO;
import com.atom.common.mb.entity.dj.DjTrackmessageDO;
import com.atom.common.mb.entity.dj.DjWhrlxxxDO;
import com.atom.common.mb.entity.dj.DjWhsxDO;
import com.atom.common.mb.entity.dj.DjXzxxDO;
import com.atom.common.mb.entity.dj.DjXzyxDO;
import com.atom.common.mb.entity.dj.DjYxxxDO;
import com.atom.common.mb.entity.gl.DbrwDO;
import com.atom.common.mb.entity.gl.GcxxDO;
import com.atom.common.mb.entity.gl.MultimediaDO;
import com.atom.common.mb.entity.gl.TrackmessageDO;
import com.atom.common.mb.entity.gl.WhrlxxxDO;
import com.atom.common.mb.entity.gl.WhsxDO;
import com.atom.common.mb.entity.gl.XzxxDO;
import com.atom.common.mb.entity.gl.XzyxDO;
import com.atom.common.mb.entity.gl.YxxxDO;
import com.atom.common.remote.user.UserUtil;
import com.atom.common.service.AbstractAvensCommonService;
import com.atom.process.cnmuseum.bm.dao.dj.DjBmDao;
import com.atom.process.cnmuseum.bm.dao.process.BmDbrwProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmGcxxProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmMultimediaProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmTrackmessageProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmWhrlxxxProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmWhsxProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmXzxxProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmXzyxProcessDao;
import com.atom.process.cnmuseum.bm.dao.process.BmYxxxProcessDao;
import com.atom.process.cnmuseum.bm.dao.task.BmDbrwTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmGcxxTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmMultimediaTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmTrackmessageTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmWhrlxxxTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmWhsxTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmXzxxTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmXzyxTaskDao;
import com.atom.process.cnmuseum.bm.dao.task.BmYxxxTaskDao;
import com.atom.process.cnmuseum.bm.entity.process.BmDbrwProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmGcxxProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmMultimediaProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmTrackmessageProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmWhrlxxxProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmWhsxProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmXzxxProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmXzyxProcessDO;
import com.atom.process.cnmuseum.bm.entity.process.BmYxxxProcessDO;
import com.atom.process.cnmuseum.bm.entity.task.BmDbrwTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmGcxxTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmMultimediaTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmTrackmessageTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmWhrlxxxTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmWhsxTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmXzxxTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmXzyxTaskDO;
import com.atom.process.cnmuseum.bm.entity.task.BmYxxxTaskDO;
import com.atom.process.cnmuseum.bm.render.BMRender;
import com.atom.process.cnmuseum.bm.tool.UserResolver;
import com.atom.process.cnmuseum.bm.vo.request.GcxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.RequestVO;
import com.atom.process.cnmuseum.bm.vo.request.WhrlxxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.XzxxRequestVO;
import com.atom.process.cnmuseum.bm.vo.request.YxxxRequestVO;
import com.sinosoft.cnmuseum.servlets.MbXtglBaseTableServlet;
import com.sinosoft.cnmuseum.utils.LogUtils;

public abstract class AbstractService extends AbstractAvensCommonService {
	@Resource
	BmProcessDao bmProcessDao;
	@Resource
	BmTaskDao bmTaskDao;
	@Resource
	DjBmDao djBmDao;

	@Resource
	BmGcxxProcessDao bmGcxxProcessDao;
	@Resource
	BmGcxxTaskDao bmGcxxTaskDao;
	@Resource
	DjGcxxDao djGcxxDao;
	@Resource
	GcxxDao gcxxDao;

	@Resource
	BmXzxxProcessDao bmXzxxProcessDao;
	@Resource
	BmXzxxTaskDao bmXzxxTaskDao;
	@Resource
	DjXzxxDao djXzxxDao;
	@Resource
	XzxxDao xzxxDao;

	@Resource
	BmYxxxProcessDao bmYxxxProcessDao;
	@Resource
	BmYxxxTaskDao bmYxxxTaskDao;
	@Resource
	DjYxxxDao djYxxxDao;
	@Resource
	YxxxDao yxxxDao;

	@Resource
	BmWhrlxxxProcessDao bmWhrlxxxProcessDao;
	@Resource
	BmWhrlxxxTaskDao bmWhrlxxxTaskDao;
	@Resource
	DjWhrlxxxDao djWhrlxxxDao;
	@Resource
	WhrlxxxDao whrlxxxDao;

	@Resource
	BmDbrwProcessDao bmDbrwProcessDao;
	@Resource
	BmDbrwTaskDao bmDbrwTaskDao;
	@Resource
	DjDbrwDao djDbrwDao;
	@Resource
	DbrwDao dbrwDao;
	
	
	@Resource
	BmMultimediaProcessDao bmMultimediaProcessDao;
	@Resource
	BmMultimediaTaskDao bmMultimediaTaskDao;
	@Resource
	DjMultimediaDao djMultimediaDao;
	@Resource
	MultimediaDao multimediaDao;
	
	
	@Resource
	BmTrackmessageProcessDao bmTrackmessageProcessDao;
	@Resource
	BmTrackmessageTaskDao bmTrackmessageTaskDao;
	@Resource
	DjTrackmessageDao djTrackmessageDao;
	@Resource
	TrackmessageDao trackmessageDao;
	
	
	@Resource
	BmXzyxProcessDao bmXzyxProcessDao;
	@Resource
	BmXzyxTaskDao bmXzyxTaskDao;
	@Resource
	DjXzyxDao djXzyxDao;
	@Resource
	XzyxDao xzyxDao;
	

	@Resource
	BmWhsxProcessDao bmWhsxProcessDao;
	@Resource
	BmWhsxTaskDao bmWhsxTaskDao;
	@Resource
	DjWhsxDao djWhsxDao;
	@Resource
	WhsxDao whsxDao;

	@Resource
	UserResolver userResolver;
	@Resource
	BMRender render;
	@Resource
	protected RunningTaskHandler runningTaskHandler;
	@Resource
	protected HistoricTaskHandler historicTaskHandler;

	protected void createPdo(UserUtil user, String processInstanceId, String biaoTi, String gcxxid) {
		GcxxDO gcxx = gcxxDao.getLastById(gcxxid);
		bmProcessDao.createPDO(user, processInstanceId, biaoTi, gcxxid);
        //编辑编目日志
        LogUtils logUtils = new LogUtils();
        String desc = biaoTi+LogUtils.MbXtglSJBJ_INSERT_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), desc);
		bmGcxxProcessDao.createPDO(user, processInstanceId, gcxx);
		//馆藏基本信息编目
        String descGcxx = biaoTi+"馆藏基本信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descGcxx);

		List<XzxxDO> xzxxlist = xzxxDao.findByProperty("gcxxId", gcxxid);
		XzxxDO xzxx = new XzxxDO();
		if (xzxxlist != null && xzxxlist.size() > 0) {
			xzxx = xzxxlist.get(0);
		} else {
			xzxx.setGcxxId(gcxxid);
		}
		bmXzxxProcessDao.createPDO(user, processInstanceId, biaoTi, xzxx);
		//形制信息编目
        String descXzxx = biaoTi+"形制信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descXzxx);

		List<YxxxDO> yxxxlist = yxxxDao.findByProperty("gcxxId", gcxxid);
		YxxxDO yxxx = new YxxxDO();
		if (yxxxlist != null && yxxxlist.size() > 0) {
			yxxx = yxxxlist.get(0);
		} else {
			yxxx.setGcxxId(gcxxid);
		}
		bmYxxxProcessDao.createPDO(user, processInstanceId, biaoTi, yxxx);
		//音响信息编目
        String descYxxx = biaoTi="音响信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descYxxx);

		List<WhrlxxxDO> whrlxxxlist = whrlxxxDao.findByProperty("gcxxId", gcxxid);
		WhrlxxxDO whrlxxx = new WhrlxxxDO();
		if (whrlxxxlist != null && whrlxxxlist.size() > 0) {
			whrlxxx = whrlxxxlist.get(0);
		} else {
			whrlxxx.setGcxxId(gcxxid);
		}
		bmWhrlxxxProcessDao.createPDO(user, processInstanceId, biaoTi, whrlxxx);
		//文化人类信息
        //生成日志
        String descWhrlxxx = biaoTi+"人文信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_update), LogUtils.model_sjbj, user.getUserid(), descWhrlxxx);

		List<DbrwDO> dbrwlist = dbrwDao.findByProperty("gcxxId", gcxxid);
		if (dbrwlist != null && dbrwlist.size() > 0) {
			for(DbrwDO dbrw:dbrwlist){
				bmDbrwProcessDao.createPDO(user, processInstanceId, biaoTi, dbrw);
		        //代表人物生成日志
		        String descDbrw = biaoTi+"代表人物"+LogUtils.MbXtglSJBJ_INSERT_DESC;
		        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descDbrw);
			}
		} 
		
		//多媒体
		List<MultimediaDO> multimedialist = multimediaDao.findByProperty("gcxxId", gcxxid);
		if (multimedialist != null && multimedialist.size() > 0) {
			for(MultimediaDO multimedia:multimedialist){
				bmMultimediaProcessDao.createPDO(user, processInstanceId, biaoTi, multimedia);
		        //多媒体信息生成日志
		        String descMultimedia = biaoTi+"多媒体信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
		        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descMultimedia);
			}
		} 
		
		//曲目
		List<TrackmessageDO> trackmessagelist = trackmessageDao.findByProperty("gcxxId", gcxxid);
		if (trackmessagelist != null && trackmessagelist.size() > 0) {
			for(TrackmessageDO trackmessage:trackmessagelist){
				bmTrackmessageProcessDao.createPDO(user, processInstanceId, biaoTi, trackmessage);
		        //曲目信息生成日志
		        String descTrackmessage = biaoTi+"曲目信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
		        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descTrackmessage);
			}
		} 
		
		//形制
		Map<String, Object> xzvars = new HashMap<String, Object>();
		xzvars.put("gcxxId", gcxxid);
		xzvars.put("filesign", "xz");
		List<XzyxDO> xzwjxxlist = xzyxDao.findByProperties(xzvars);
		if (xzwjxxlist != null && xzwjxxlist.size() > 0) {
			for(XzyxDO xzwjxx:xzwjxxlist){
				bmXzyxProcessDao.createPDO(user, processInstanceId, biaoTi, xzwjxx);
		        //形制信息生成日志
		        String descXzwjxx = biaoTi+"形制文件信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
		        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descXzwjxx);
			}
		} 
		
		//音响
		Map<String, Object> yxvars = new HashMap<String, Object>();
		yxvars.put("gcxxId", gcxxid);
		yxvars.put("filesign", "yx");
		List<XzyxDO> yxwjxxlist = xzyxDao.findByProperties(yxvars);
		if (yxwjxxlist != null && yxwjxxlist.size() > 0) {
			for(XzyxDO yxwjxx:yxwjxxlist){
				bmXzyxProcessDao.createPDO(user, processInstanceId, biaoTi, yxwjxx);
		        //音响信息生成日志
		        String descYxwjxx = biaoTi+"音响文件信息"+LogUtils.MbXtglSJBJ_INSERT_DESC;
		        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descYxwjxx);
			}
		} 
		
		
		
		
		List<WhsxDO> whsxlist = whsxDao.findByProperty("gcxxId", gcxxid);
		if (whsxlist != null && whsxlist.size() > 0) {
			for(WhsxDO whsx:whsxlist){
				bmWhsxProcessDao.createPDO(user, processInstanceId, biaoTi, whsx);
				//文化事项
		        String descWhsx = biaoTi+"文化事项"+LogUtils.MbXtglSJCJ_UPDATE_DESC;
		        logUtils.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjbj, user.getUserid(), descWhsx);
			}
		} 
	}

	protected void createAdo(UserUtil user, String processInstanceId, String taskId, String biaoTi, String gcxxid) {
		GcxxDO gcxx = gcxxDao.getLastById(gcxxid);

		bmTaskDao.createADO(user, processInstanceId, taskId, biaoTi, gcxxid);
		bmGcxxTaskDao.createADO(user, processInstanceId, taskId, gcxx);

		List<XzxxDO> xzxxlist = xzxxDao.findByProperty("gcxxId", gcxxid);
		XzxxDO xzxx = new XzxxDO();
		if (xzxxlist != null && xzxxlist.size() > 0) {
			xzxx = xzxxlist.get(0);
		} else {
			xzxx.setGcxxId(gcxxid);
		}
		bmXzxxTaskDao.createADO(user, processInstanceId, taskId, xzxx);


		List<YxxxDO> yxxxlist = yxxxDao.findByProperty("gcxxId", gcxxid);
		YxxxDO yxxx = new YxxxDO();
		if (yxxxlist != null && yxxxlist.size() > 0) {
			yxxx = yxxxlist.get(0);
		} else {
			yxxx.setGcxxId(gcxxid);
		}
		bmYxxxTaskDao.createADO(user, processInstanceId, taskId, yxxx);
		

		List<WhrlxxxDO> whrlxxxlist = whrlxxxDao.findByProperty("gcxxId", gcxxid);
		WhrlxxxDO whrlxxx = new WhrlxxxDO();
		if (whrlxxxlist != null && whrlxxxlist.size() > 0) {
			whrlxxx = whrlxxxlist.get(0);
		} else {
			whrlxxx.setGcxxId(gcxxid);
		}
		bmWhrlxxxTaskDao.createADO(user, processInstanceId, taskId, whrlxxx);
		

		List<DbrwDO> dbrwlist = dbrwDao.findByProperty("gcxxId", gcxxid);
		if (dbrwlist != null && dbrwlist.size() > 0) {
			for(DbrwDO dbrw:dbrwlist){
				bmDbrwTaskDao.createADO(user, processInstanceId, taskId, dbrw);
			}
		}
		
		//多媒体信息		
		List<MultimediaDO> multimedialist = multimediaDao.findByProperty("gcxxId", gcxxid);
		if (multimedialist != null && multimedialist.size() > 0) {
			for(MultimediaDO multimedia:multimedialist){
				bmMultimediaTaskDao.createADO(user, processInstanceId, taskId, multimedia);
			}
		} 
		
		//曲目信息
		List<TrackmessageDO> trackmessagelist = trackmessageDao.findByProperty("gcxxId", gcxxid);
		if (trackmessagelist != null && trackmessagelist.size() > 0) {
			for(TrackmessageDO trackmessage:trackmessagelist){
				bmTrackmessageTaskDao.createADO(user, processInstanceId, taskId, trackmessage);
			}
		} 
		
		
		//形制信息
		Map<String, Object> xzvars = new HashMap<String, Object>();
		xzvars.put("gcxxId", gcxxid);
		xzvars.put("filesign", "xz");
		List<XzyxDO> xzwjxxlist = xzyxDao.findByProperties(xzvars);
		if (xzwjxxlist != null && xzwjxxlist.size() > 0) {
			for(XzyxDO xzwjxx:xzwjxxlist){
				bmXzyxTaskDao.createADO(user, processInstanceId, taskId, xzwjxx);
			}
		}
		
		//音响信息
		Map<String, Object> yxvars = new HashMap<String, Object>();
		yxvars.put("gcxxId", gcxxid);
		yxvars.put("filesign", "yx");
		List<XzyxDO> yxwjxxlist = xzyxDao.findByProperties(xzvars);
		if (yxwjxxlist != null && yxwjxxlist.size() > 0) {
			for(XzyxDO yxwjxx:yxwjxxlist){
				bmXzyxTaskDao.createADO(user, processInstanceId, taskId, yxwjxx);
			}
		}
		
		
		
		List<WhsxDO> whsxlist = whsxDao.findByProperty("gcxxId", gcxxid);
		if (whsxlist != null && whsxlist.size() > 0) {
			for(WhsxDO whsx:whsxlist){
				bmWhsxTaskDao.createADO(user, processInstanceId, taskId, whsx);
			}
		} 
	}

	protected void saveAdo(String taskId, RequestVO vo, GcxxRequestVO gcxxvo, XzxxRequestVO xzxxvo,
			YxxxRequestVO yxxxvo,WhrlxxxRequestVO whrlxxxvo, UserUtil user,String title) {
		BmTaskDO bm_ado = bmTaskDao.findByTaskId(taskId);
		BeanUtils.copyProperties(vo, bm_ado, "id", "taskId", "processId");
		bm_ado.setYourAdvice(vo.getYourAdvice());
		bmTaskDao.update(bm_ado);
        //编辑编目日志
        LogUtils logUtils = new LogUtils();
        String desc = title+LogUtils.MbXtglSJBJ_UPDATE_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_update), LogUtils.model_sjbj, user.getUserid(), desc);
		// 馆藏信息
		BmGcxxTaskDO ado = bmGcxxTaskDao.findByTaskId(taskId);
		BeanUtils.copyProperties(gcxxvo, ado, "id", "taskId", "processId");
        String year = gcxxvo.getYear();
        String yearText = new MbXtglBaseTableServlet().getNdTextById(year);
        ado.setYear_text(yearText);
		bmGcxxTaskDao.update(ado);
		//生成日志
        String descGcxx = title+"馆藏基本信息"+LogUtils.MbXtglSJBJ_UPDATE_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_update), LogUtils.model_sjbj, user.getUserid(), descGcxx);
		BmXzxxTaskDO xzado = bmXzxxTaskDao.findByTaskId(taskId);
		BeanUtils.copyProperties(xzxxvo, xzado, "id", "taskId", "processId");
		bmXzxxTaskDao.update(xzado);
        //生成日志
        String descjXzxx = title+"形制信息"+LogUtils.MbXtglSJBJ_UPDATE_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_update), LogUtils.model_sjbj, user.getUserid(), descjXzxx);
		// 音响信息
		BmYxxxTaskDO yxado = bmYxxxTaskDao.findByTaskId(taskId);
		BeanUtils.copyProperties(yxxxvo, yxado, "id", "taskId", "processId");
		bmYxxxTaskDao.update(yxado);
        //生成日志
        String descYxxx = title+"音响信息"+LogUtils.MbXtglSJBJ_UPDATE_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_update), LogUtils.model_sjbj, user.getUserid(), descYxxx);
		// 人文信息
		BmWhrlxxxTaskDO whrlxxxado = bmWhrlxxxTaskDao.findByTaskId(taskId);
		BeanUtils.copyProperties(whrlxxxvo, whrlxxxado, "id", "taskId", "processId");
		bmWhrlxxxTaskDao.update(whrlxxxado);
        //生成日志
        String descWhrlxxx = title+"人文信息"+LogUtils.MbXtglSJBJ_UPDATE_DESC;
        logUtils.addLog(String.valueOf(LogUtils.type_update), LogUtils.model_sjbj, user.getUserid(), descWhrlxxx);
	}

	protected void ADO2PDO(String mainProcessInstanceId, String taskId) {
		BmTaskDO bm_ado = bmTaskDao.findByTaskId(taskId);
		BmProcessDO bm_pdo = bmProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		BeanUtils.copyProperties(bm_ado, bm_pdo, "id");
		bmProcessDao.update(bm_pdo);
		// 馆藏信息
		BmGcxxTaskDO ado = bmGcxxTaskDao.findByTaskId(taskId);
		BmGcxxProcessDO pdo = bmGcxxProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		BeanUtils.copyProperties(ado, pdo, "id");
		bmGcxxProcessDao.update(pdo);

		BmXzxxTaskDO xzado = bmXzxxTaskDao.findByTaskId(taskId);
		BmXzxxProcessDO xzpdo = bmXzxxProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		BeanUtils.copyProperties(xzado, xzpdo, "id");
		bmXzxxProcessDao.update(xzpdo);
		// 音响信息
		BmYxxxTaskDO yxado = bmYxxxTaskDao.findByTaskId(taskId);
		BmYxxxProcessDO yxpdo = bmYxxxProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		BeanUtils.copyProperties(yxado, yxpdo, "id");
		bmYxxxProcessDao.update(yxpdo);
		// 文化人类学信息
		BmWhrlxxxTaskDO whrlxxxado = bmWhrlxxxTaskDao.findByTaskId(taskId);
		BmWhrlxxxProcessDO whrlxxxpdo = bmWhrlxxxProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		BeanUtils.copyProperties(whrlxxxado, whrlxxxpdo, "id");
		bmWhrlxxxProcessDao.update(whrlxxxpdo);

		List<BmDbrwProcessDO> dbrwpdo_list = bmDbrwProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		for (BmDbrwProcessDO dbrwpdo : dbrwpdo_list) {
			bmDbrwProcessDao.delete(dbrwpdo);
		}
		List<BmDbrwTaskDO> dbrwado_list = bmDbrwTaskDao.findByTaskId(taskId);
		for (BmDbrwTaskDO dbrwado : dbrwado_list) {
			BmDbrwProcessDO dbrwpdo = new BmDbrwProcessDO();
			BeanUtils.copyProperties(dbrwado, dbrwpdo, "id");
			bmDbrwProcessDao.save(dbrwpdo);
		}
		
		//多媒体信息
		List<BmMultimediaProcessDO> multimediapdo_list = bmMultimediaProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		for (BmMultimediaProcessDO multimediapdo : multimediapdo_list) {
			bmMultimediaProcessDao.delete(multimediapdo);
		}
		List<BmMultimediaTaskDO> multimediaado_list = bmMultimediaTaskDao.findByTaskId(taskId);
		for (BmMultimediaTaskDO multimediaado : multimediaado_list) {
			BmMultimediaProcessDO multimediapdo = new BmMultimediaProcessDO();
			BeanUtils.copyProperties(multimediaado, multimediapdo, "id");
			bmMultimediaProcessDao.save(multimediapdo);
		}
		
		//曲目信息
		List<BmTrackmessageProcessDO> trackmessagepdo_list = bmTrackmessageProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		for (BmTrackmessageProcessDO trackmessagepdo : trackmessagepdo_list) {
			bmTrackmessageProcessDao.delete(trackmessagepdo);
		}
		List<BmTrackmessageTaskDO> trackmessageado_list = bmTrackmessageTaskDao.findByTaskId(taskId);
		for (BmTrackmessageTaskDO trackmessageado : trackmessageado_list) {
			BmTrackmessageProcessDO trackmessagepdo = new BmTrackmessageProcessDO();
			BeanUtils.copyProperties(trackmessageado, trackmessagepdo, "id");
			bmTrackmessageProcessDao.save(trackmessagepdo);
		}
		
		//形制信息		
		List<BmXzyxProcessDO> xzwjxxpdo_list = bmXzyxProcessDao.findByProcessInstanceIdAndFilesign(mainProcessInstanceId,"xz");
		for (BmXzyxProcessDO xzwjxxpdo : xzwjxxpdo_list) {
			bmXzyxProcessDao.delete(xzwjxxpdo);
		}
		List<BmXzyxTaskDO> xzwjxxado_list = bmXzyxTaskDao.findByTaskIdAndFilesign(taskId,"xz");
		for (BmXzyxTaskDO xzwjxxado : xzwjxxado_list) {
			BmXzyxProcessDO xzwjxxpdo = new BmXzyxProcessDO();
			BeanUtils.copyProperties(xzwjxxado, xzwjxxpdo, "id");
			bmXzyxProcessDao.save(xzwjxxpdo);
		}
		
		//音响信息
		List<BmXzyxProcessDO> yxwjxxpdo_list = bmXzyxProcessDao.findByProcessInstanceIdAndFilesign(mainProcessInstanceId,"xz");
		for (BmXzyxProcessDO yxwjxxpdo : yxwjxxpdo_list) {
			bmXzyxProcessDao.delete(yxwjxxpdo);
		}
		List<BmXzyxTaskDO> yxwjxxado_list = bmXzyxTaskDao.findByTaskIdAndFilesign(taskId,"xz");
		for (BmXzyxTaskDO yxwjxxado : yxwjxxado_list) {
			BmXzyxProcessDO yxwjxxpdo = new BmXzyxProcessDO();
			BeanUtils.copyProperties(yxwjxxado, yxwjxxpdo, "id");
			bmXzyxProcessDao.save(yxwjxxpdo);
		}
		
		

		List<BmWhsxProcessDO> whsxpdo_list = bmWhsxProcessDao.findByProcessInstanceId(mainProcessInstanceId);
		for (BmWhsxProcessDO whsxpdo : whsxpdo_list) {
			bmWhsxProcessDao.delete(whsxpdo);
		}
		List<BmWhsxTaskDO> whsxado_list = bmWhsxTaskDao.findByTaskId(taskId);
		for (BmWhsxTaskDO whsxado : whsxado_list) {
			BmWhsxProcessDO whsxpdo = new BmWhsxProcessDO();
			BeanUtils.copyProperties(whsxado, whsxpdo, "id");
			bmWhsxProcessDao.save(whsxpdo);
		}

	}

	protected void guidang(String processId) {

		String gcxxid = "";
		// 结束之后更新原标志
		List<BmProcessDO> bmlist = bmProcessDao.findByProperty("processId", processId);
		if (bmlist != null && bmlist.size() > 0) {
			BmProcessDO bm = bmlist.get(0);
			gcxxid = bm.getGcxxid();
		}

		if (!gcxxid.equals("")) {
			GcxxDO Lastgcxx = gcxxDao.getLastById(gcxxid);
			Lastgcxx.setIsNew("0");
			Lastgcxx.setIsRunning("0");
			gcxxDao.update(Lastgcxx);

			GcxxDO gcxx = new GcxxDO();
			BmGcxxProcessDO pdo_gcxx = bmGcxxProcessDao.findByProcessInstanceId(processId);
			DjGcxxDO dj_gcxx = new DjGcxxDO();
			BeanUtils.copyProperties(pdo_gcxx, dj_gcxx, "id");
			djGcxxDao.save(dj_gcxx);
			BeanUtils.copyProperties(pdo_gcxx, gcxx, "id");
			gcxx.setIsNew("1");
			String newgcxxid = (String) gcxxDao.save(gcxx);

			BmXzxxProcessDO pdo_xzxx = bmXzxxProcessDao.findByProcessInstanceId(processId);
			DjXzxxDO dj_xzxx = new DjXzxxDO();
			BeanUtils.copyProperties(pdo_xzxx, dj_xzxx, "id");
			dj_xzxx.setGcxxId(dj_gcxx.getId()+"");
			djXzxxDao.save(dj_xzxx);
			XzxxDO xzxx = new XzxxDO();
			BeanUtils.copyProperties(pdo_xzxx, xzxx, "id");
			xzxx.setGcxxId(newgcxxid);
			xzxxDao.save(xzxx);
			// 音响信息
			BmYxxxProcessDO pdo_yxxx = bmYxxxProcessDao.findByProcessInstanceId(processId);
			DjYxxxDO dj_yxxx = new DjYxxxDO();
			BeanUtils.copyProperties(pdo_yxxx, dj_yxxx, "id");
			djYxxxDao.save(dj_yxxx);
			YxxxDO yxxx = new YxxxDO();
			BeanUtils.copyProperties(pdo_yxxx, yxxx, "id");
			yxxx.setGcxxId(newgcxxid);
			yxxxDao.save(yxxx);

			BmWhrlxxxProcessDO pdo_whrlxxx = bmWhrlxxxProcessDao.findByProcessInstanceId(processId);
			DjWhrlxxxDO dj_whrlxxx = new DjWhrlxxxDO();
			BeanUtils.copyProperties(pdo_whrlxxx, dj_whrlxxx, "id");
			djWhrlxxxDao.save(dj_whrlxxx);
			WhrlxxxDO whrlxxx = new WhrlxxxDO();
			BeanUtils.copyProperties(pdo_whrlxxx, whrlxxx, "id");
			whrlxxx.setGcxxId(newgcxxid);
			whrlxxxDao.save(whrlxxx);

			List<BmDbrwProcessDO> dbrwpdo_list = bmDbrwProcessDao.findByProcessInstanceId(processId);
			for (BmDbrwProcessDO dbrwpdo : dbrwpdo_list) {
				DjDbrwDO dj_dbrw = new DjDbrwDO();
				BeanUtils.copyProperties(dbrwpdo, dj_dbrw, "id");
				djDbrwDao.save(dj_dbrw);
				DbrwDO dbrw = new DbrwDO();
				BeanUtils.copyProperties(dbrwpdo, dbrw, "id");
				dbrw.setGcxxId(newgcxxid);
				dbrwDao.save(dbrw);

			}
			
			//多媒体信息
			List<BmMultimediaProcessDO> multimediapdo_list = bmMultimediaProcessDao.findByProcessInstanceId(processId);
			for (BmMultimediaProcessDO multimediapdo : multimediapdo_list) {
				DjMultimediaDO dj_multimedia = new DjMultimediaDO();
				BeanUtils.copyProperties(multimediapdo, dj_multimedia, "id");
				djMultimediaDao.save(dj_multimedia);
				MultimediaDO multimedia = new MultimediaDO();
				BeanUtils.copyProperties(multimediapdo, multimedia, "id");
				multimedia.setGcxxId(newgcxxid);
				multimediaDao.save(multimedia);
			}
			
			//曲目信息
			List<BmTrackmessageProcessDO> trackmessagepdo_list = bmTrackmessageProcessDao.findByProcessInstanceId(processId);
			for (BmTrackmessageProcessDO trackmessagepdo : trackmessagepdo_list) {
				DjTrackmessageDO dj_trackmessage = new DjTrackmessageDO();
				BeanUtils.copyProperties(trackmessagepdo, dj_trackmessage, "id");
				djTrackmessageDao.save(dj_trackmessage);
				TrackmessageDO trackmessage = new TrackmessageDO();
				BeanUtils.copyProperties(trackmessagepdo, trackmessage, "id");
				trackmessage.setGcxxId(newgcxxid);
				trackmessageDao.save(trackmessage);
			}
			
			//形制信息
			List<BmXzyxProcessDO> xzwjxxpdo_list = bmXzyxProcessDao.findByProcessInstanceIdAndFilesign(processId,"xz");
			for (BmXzyxProcessDO xzwjxxpdo : xzwjxxpdo_list) {
				DjXzyxDO dj_xzwjxx = new DjXzyxDO();
				BeanUtils.copyProperties(xzwjxxpdo, dj_xzwjxx, "id");
				djXzyxDao.save(dj_xzwjxx);
				XzyxDO xzwjxx = new XzyxDO();
				BeanUtils.copyProperties(xzwjxxpdo, xzwjxx, "id");
				xzwjxx.setGcxxId(newgcxxid);
				xzyxDao.save(xzwjxx);
			}
			
			//音响信息
			List<BmXzyxProcessDO> yxwjxxpdo_list = bmXzyxProcessDao.findByProcessInstanceIdAndFilesign(processId,"yx");
			for (BmXzyxProcessDO yxwjxxpdo : yxwjxxpdo_list) {
				DjXzyxDO dj_yxwjxx = new DjXzyxDO();
				BeanUtils.copyProperties(yxwjxxpdo, dj_yxwjxx, "id");
				djXzyxDao.save(dj_yxwjxx);
				XzyxDO yxwjxx = new XzyxDO();
				BeanUtils.copyProperties(yxwjxxpdo, yxwjxx, "id");
				yxwjxx.setGcxxId(newgcxxid);
				xzyxDao.save(yxwjxx);
			}
			


			List<BmWhsxProcessDO> whsxpdo_list = bmWhsxProcessDao.findByProcessInstanceId(processId);
			for (BmWhsxProcessDO whsxpdo : whsxpdo_list) {
				DjWhsxDO dj_whsx = new DjWhsxDO();
				BeanUtils.copyProperties(whsxpdo, dj_whsx, "id");
				djWhsxDao.save(dj_whsx);
				WhsxDO whsx = new WhsxDO();
				BeanUtils.copyProperties(whsxpdo, whsx, "id");
				whsx.setGcxxId(newgcxxid);
				whsxDao.save(whsx);

			}
		}

	}

	protected void updateGcxxBmbs(String gcxxid, String bmbs) {
		GcxxDO gcxx = gcxxDao.getLastById(gcxxid);
		gcxx.setIsRunning(bmbs);
		gcxxDao.update(gcxx);
	}
}
